package com.neusoft.cmsprojects.util;

import javax.annotation.Resource;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.cmsprojects.model.Privilege;

/**
 * 安装必要的信息
 * 
 * Install<BR>
 * 创建人:许耀东 <BR>
 * 时间：2014年12月22日-上午11:01:08 <BR>
 * @version 1.0.0
 *
 */
@Component
public class Install {
	/**初始化数据
	 * @param args
	 */
	@Resource
	private SessionFactory sessionfactory;
	
	@Transactional
	public void install(){
		
		Session session = sessionfactory.getCurrentSession();

		Privilege menu, menu1, menu2, menu3, menu4, menu5;
		
		/*menu=new Privilege("文章管理", null, null);
		
		menu1=new Privilege("添加文章", "/art_add.action", menu);
		menu2=new Privilege("管理文章", "/art_list.action", menu);
		menu3=new Privilege("添加文章类别", "/art_addtype.action", menu);
		menu4=new Privilege("管理文章类别", "/art_listtype.action", menu);
		session.save(menu);
		session.save(menu1);
		session.save(menu2);
		session.save(menu3);
		session.save(menu4);
		*/
		
		
        menu=new Privilege("产品管理", null, null);
		
		menu1=new Privilege("添加产品", "/product_add.action", menu);
		menu2=new Privilege("管理产品", "/product_list.action", menu);
		menu3=new Privilege("添加产品类别", "/product_addtype.action", menu);
		menu4=new Privilege("管理产品类别", "/product_listtype.action", menu);
		session.save(menu);
		session.save(menu1);
		session.save(menu2);
		session.save(menu3);
		session.save(menu4);
		
		
		menu=new Privilege("留言管理", null, null);
		
		menu1=new Privilege("查看留言", "/mesg_list.action", menu);
		session.save(menu);
		session.save(menu1);
		
		menu=new Privilege("用户管理", null, null);
			
		menu1=new Privilege("添加用户", "/User_addPage.action", menu);
		menu2=new Privilege("管理用户", "/User_list.action", menu);
		menu3=new Privilege("权限设置", "/User_privilegePage.action", menu);
		session.save(menu);
		session.save(menu1);
		session.save(menu2);
		session.save(menu3);
		
	}
	
	public static void main(String[] args) {
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		Install install = (Install) ac.getBean("install");
		install.install();
	}
}

